<?php

namespace app\admin\controller;

use app\admin\model\Store;

use think\Request;

class Storesettlement extends Base
{

    public function getlist(){
        $params = $this->request->param();
        $where = [];
        if(isset($params['begin_time']) && $params['begin_time']){
            $where['withdrawalTime'] = ['egt', $params['begin_time']];
        }
        if(isset($params['end_time']) && $params['end_time']){
            $where['withdrawalTime'] = ['lt', $params['end_time'] . ' 23:59:59'];
        }
        if(isset($params['begin_time']) && $params['begin_time'] && isset($params['end_time']) && $params['end_time']){
            $where['withdrawalTime'] = [['egt', $params['begin_time']], ['lt', $params['end_time'] . ' 23:59:59'], 'and'];
        }

        $model = model('Storesettlement');
        $list = $model->where($where)->order('withdrawalTime DESC')->paginate(10);
        $total = $model->where($where)->count();

        if($list){
            foreach ($list as $item) {
                $item['storeName'] = Store::where('id', $item['storeId'])->value('name');
                /*switch ($item['status']) {
                    case 0:
                        $item['status'] = '待结算'; break;
                    case 1:
                        $item['status'] = '已结算'; break;
                    default: break;
                }*/
            }
        }

        return $this->fetch('',[
            'datas' => $list,
            'total' => $total,
            'formget' => $_GET
        ]);
    }

}